/*
 * Created by SharpDevelop.
 * user: Robertux
 * Date: 18/03/2008
 * Time: 13:42
 * 
 * 
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using DataLayer;
using Inventador;

namespace WinApp
{
	/// <summary>
	/// Description of AddEditUsr.
	/// </summary>
	public partial class frmAddUsr : Form
	{
		private BaseDatos bdatos;
		
		public frmAddUsr()
		{
			InitializeComponent();
		}
		
		public frmAddUsr(BaseDatos bdatosExterna): this()
		{
			this.bdatos = bdatosExterna;
		}
		
		void Button1Click(object sender, EventArgs e)
		{
			this.Close();
		}
		
		void Button2Click(object sender, EventArgs e)
		{
			if(this.txtClave.Text != this.txtRepetirClave.Text)
				MessageBox.Show("Las claves no coinciden","Error");
			else
			{
				if(this.txtNombreUsuario.Text == "" || this.txtClave.Text == "" || this.txtRepetirClave.Text == "")
					MessageBox.Show("Todos los campos son requeridos","Error");
				else
				{
					int maxId = Usuario.GetMaxID(this.bdatos);
					Usuario newUsr = new Usuario(maxId + 1, this.txtNombreUsuario.Text, this.txtClave.Text, "n");
					newUsr.Insert(this.bdatos);
					this.Close();
				}
			}			
		}
	}
}
